package com.addplus.townmall.server.api.mapper.town;

import com.addplus.townmall.server.api.model.town.GiftMemberCard;
import com.addplus.townmall.server.api.model.town.expand.GiftMemberCardExpand;
import com.addplus.townmall.server.api.utils.BaseAddMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 商城礼品用户表 Mapper 接口
 * </p>
 *
 * @author zhangjiehang
 * @since 2018-11-23
 */
public interface GiftMemberCardMapper extends BaseAddMapper<GiftMemberCard> {


    @Select("SELECT\n" +
            " c.id,\n" +
            " c.member_id,\n" +
            " c.use_member_id,\n" +
            " c.gift_status,\n" +
            " c.gift_card_name,\n" +
            " c.gift_card_img,\n" +
            " c.gift_value,\n" +
            " b.gift_card_id \n" +
            "FROM\n" +
            " gift_member_card c\n" +
            " INNER JOIN gift_batch_card b ON b.id = c.gift_batch_card_id \n" +
            " AND b.is_delete = 0 AND b.gift_status =1\n" +
            "WHERE\n" +
            " c.member_id = #{memberId} \n" +
            " AND c.is_delete = 0 \n" +
            "ORDER BY\n" +
            " c.gmt_create DESC")
    List<GiftMemberCardExpand> getBuyMemberGiftCard(Page page, @Param("memberId") Integer memberId);

}
